// import request from 'umi-request';
import request from '@/utils/request';
import requestString from '@/utils/requestString.tsx';
import { TableListParams } from './data.d';

export async function queryOrders(params: TableListParams) {
  return request(MC_PATH + '/api/orders/website', {
    params,
  });
}

/**
 * 创建订单
 * @param order
 * @returns {Promise.<Object>}
 */
export async function createOrder(data) {
  return requestString(MC_PATH + '/api/order/website', {
    method: 'POST',
    data,
  });
}

/**
 * 修改订单
 * @param order
 * @returns {Promise.<Object>}
 */
export async function updateOrder(data) {
  return requestString(MC_PATH + '/api/order/website', {
    method: 'PUT',
    data,
  });
}

/**
 * 根据id查询订单信息
 *
 * @param id
 * @returns {Promise.<void>}
 */
export async function getOrderById({ id }) {
  return request(MC_PATH + '/api/order/website/' + id, {
    method: 'GET',
    data: { id },
  });
}

/**
 * 根据id删除订单
 *
 * @param id
 * @returns {Promise.<void>}
 */
export async function deleteOrderById({ id }) {
  return request(MC_PATH + '/api/order/' + id, {
    method: 'DELETE',
    data: { id },
  });
}

/**
 * 分页查询产品
 *
 * @param cstId
 * @param productName
 * @param status
 * @param productPage
 * @returns {Promise.<Object>}
 */
export async function queryProductList(data) {
  return request(MC_PATH + '/api/products', {
    method: 'GET',
    data,
  });
}

/**
 * 查询个人客户
 *
 * @param sprCode
 * @returns {Promise.<void>}
 */
export async function queryPrivateCustomersList(data) {
  return request(MC_PATH + '/api/privateCustomer/all', {
    method: 'GET',
    data,
  });
}

/**
 * 查询境外买家
 *
 * @param data
 * @returns {Promise.<void>}
 */
export async function queryBuyersList(data) {
  return request(MC_PATH + '/api/buyers/all', {
    method: 'GET',
    data,
  });
}

/**
 * 查询境内货源地
 *
 * @param data
 * @returns {Promise.<void>}
 */
export async function querySupplygoodList(data) {
  return request(MC_PATH + '/api/drawer/supplygoods', {
    method: 'GET',
    data,
  });
}

/**
 * 查询开票人
 *
 * @param data
 * @returns {Promise.<void>}
 */
export async function queryDrawersList(data) {
  return request(MC_PATH + '/api/drawers/all', {
    method: 'GET',
    data,
  });
}

/**
 * 根据sprCode获取参数集合
 *
 * @param sprCode
 * @returns {Promise.<void>}
 */
export async function getBusinessParamsByCode({ sprCode }) {
  return request(BASEDATA_PATH + '/api/allBusinessParams', {
    method: 'GET',
    data: { sprCode },
  });
}

/**
 * 获取所有币种信息
 *
 * @returns {Promise.<void>}
 */
export async function getAllCurrencys() {
  return request(BASEDATA_PATH + '/api/allCurrency', {
    method: 'GET',
  });
}

/**
 * 查询所有海关口岸
 *
 * @param status
 * @returns {Promise.<Object>}
 */
export async function getAllPorts({ status }) {
  return request(BASEDATA_PATH + '/api/allPlaceClearance', {
    method: 'GET',
    data: { status },
  });
}

export async function removeRule(params: TableListParams) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'delete',
    },
  });
}

export async function addRule(params: TableListParams) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'post',
    },
  });
}

export async function updateRule(params: TableListParams) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}

/**
 * 新增报关抬头
 * @param data
 * @returns {Promise<any>}
 */
export async function createPrivateCustomer(data) {
  return request(MC_PATH + '/api/privateCustomer', {
    method: 'POST',
    requestType:'form',
    data,
  });
}

/**
 * 新增境外贸易商
 * @param data
 * @returns {Promise<any>}
 */
export async function createBuyer(data) {
  return requestString(MC_PATH + '/api/buyer', {
    method: 'POST',
    data,
  });
}

/**
 * 创建开票工厂
 * @param order
 * @returns {Promise.<Object>}
 */
export async function createDrawer(data) {
  return request(MC_PATH + '/api/drawer', {
    method: 'POST',
    requestType:'form',
    data,
  });
}
